<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>文章信息管理</title>
    <script type="text/javascript" src="/static/js/jquery.js"></script>
    <script type="text/javascript" src="/static/js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/static/js/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="/static/js/MyAjaxForm.js"></script>
    <script src="/static/js/jquery.unobtrusive-ajax.min.js" type="text/javascript"></script>
    <link href="/static/css/themes/default/easyui.css" rel="stylesheet"/>
    <link href="/static/css/themes/icon.css" rel="stylesheet"/>
    <script type="text/javascript">
        $(function () {
            $("#addDiv").css("display","none");
            loadData();
        });
        function loadData() {
            $('#tt').datagrid({
                url: '/Admin/ArticleInfo/GetArticleInfo',
                title: '新闻数据表格',
                width: 700,
                height: 400,
                fitColumns: true, //列自适应
                nowrap: false,
                idField: 'Id',//主键列的列明
                loadMsg: '正在加载新闻的信息...',
                pagination: true,//是否有分页
                singleSelect: false,//是否单行选择
                pageSize: 5,//页大小，一页多少条数据
                pageNumber: 1,//当前页，默认的
                pageList: [5, 10, 15],
                queryParams: {},//往后台传递参数
                columns: [[//c.UserName, c.UserPass, c.Email, c.RegTime
                    { field: 'ck', checkbox: true, align: 'left', width: 50 },
                    { field: 'Id', title: '编号', width: 80 },
                    { field: 'Title', title: '标题', width: 120 },
                    { field: 'Author', title: '作者', width: 120 },
                    { field: 'Origin', title: '来源', width: 120 },
                    {
                        field: 'AddDate', title: '时间', width: 80, align: 'right',
                        formatter: function (value, row, index) {
                            return value.split("T")[0];
                        }
                    },
                    {
                        field: 'showDetail', title: '详细', width: 80, align: 'right',
                        formatter: function (value, row, index) {
                            var d=row.AddDate.split("T")[0];
                            // var year=d.split("-")[0];
                            // var month=d.split("-")[1];
                            // var day=d.split("-")[2];
                            // url=year+"/"+month+"/"+day;
                            var str = "<a href='#' ids='" + row.Id + "' class='details' showAddData='" +d + "'>详细</a>";
                            return str;
                        }
                    }

                ]],
                onLoadSuccess: function () {
                    $(".details").click(function () {
                        var articleId = $(this).attr("ids");
                        var showAddData = $(this).attr("showAddData");//2015/1/12
                        var dir = "/static/Article/"+showAddData+"/"+articleId+".html";
                        window.open(dir);
                    });
                },

                toolbar: [{
                    id: 'btnDelete',
                    text: '删除',
                    iconCls: 'icon-remove',
                    handler: function () {


                    }
                }, {
                    id: 'btnAdd',
                    text: '添加',
                    iconCls: 'icon-add',
                    handler: function () {
                        addArticle();//添加文章

                    }
                }, {
                    id: 'btnEdit',
                    text: '编辑',
                    iconCls: 'icon-edit',
                    handler: function () {


                    }
                }],
            });
        }
        function addArticle() {
            $("#addFrame").attr("src","/Admin/ArticleInfo/ShowAddArticleInfo");
            $("#addDiv").css("display","block");
            $('#addDiv').dialog({
                title: '添加文章信息',
                width: 800,
                height: 700,
                collapsible: true,
                maximizable: true,
                resizable: true,
                modal: true,
                buttons: [{
                    text: 'Ok',
                    iconCls: 'icon-ok',
                    handler: function () {
                        //提交表单。
                        var childWindows=$("#addFrame")[0].contentWindow;//获取子窗体的windows对象。
                        childWindows.subForm();//提交表单
                    }
                }, {
                    text: 'Cancel',
                    handler: function () {
                        $('#addDiv').dialog('close');
                    }
                }]
            });
        }
        function afterArticleAdd(data) {
            if (data.flag=="ok"){
                $.messager.alert("提示","文章添加成功！","info");
                $('#addDiv').dialog('close');
                $('#tt').datagrid("reload");
            }
        }
    </script>
</head>
<body>

<div id="addDiv">
    <iframe id="addFrame" frameborder="0" width="100%" height="100%"></iframe>
</div>

<table id="tt" style="width: 700px;" title="标题，可以使用代码进行初始化，也可以使用这种属性的方式" iconcls="icon-edit">
</table>
</body>
</html>